package com.fingard.dsp.bank.reqrespobj.elecbillquery;

import java.lang.reflect.Field;

import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.detail.RetAtsB008HistoricalBillQryDetail;
import com.fingard.xml.XmlTextWriter;

/**
 * Created by dalt on 2018/5/20.
 */
public class RetAtsB008HistoricalBillQry extends RetAtsBase {

    public String respCode;
    public String respInfo;
    private boolean flush = false;


    public RetAtsB008HistoricalBillQry(ReqRespHeader p_header) {
        retHeader = p_header;
        retXmlWriter = new XmlTextWriter();//用于输出返回ATS的XML报文
    }

    public void writeBefore() {
        writeStart();//写返回ATS的统一头部信息
    }

    public void writeAfter() {
        if (!flush) {
            retXmlWriter.writeElementString("RespCode", respCode);
            retXmlWriter.writeElementString("RespInfo", respInfo);
            flush = true;
        }
        writeEnd();
    }

    public void writeDetail(RetAtsB008HistoricalBillQryDetail detail) {
        if (!flush) {
            retXmlWriter.writeElementString("RespCode", respCode);
            retXmlWriter.writeElementString("RespInfo", respInfo);
            flush = true;
        }

        retXmlWriter.writeStartElement("DetailRecord");

        for (Field field : detail.getClass().getDeclaredFields()) {
            try {
                retXmlWriter.writeElementString(field.getName(), (String) field.get(detail));
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }

        retXmlWriter.writeEndElement();
    }

}
